Editor.Shapes.Literal = function (u) {
	this.text = '';
	this.lang = '';
	this.datatype = '';

	Editor.Shape.call(this, this, u);

		this.inProperties = new Array();

		this.corner = new Editor.Decks.CornerVocabLiteral();
		this.corner.init(this);

		this.deckEdit = new Editor.Decks.Edit();
		this.deckEdit.init(this, u);
	}

	Editor.Util.inherits(Editor.Shapes.Literal, Editor.Shape);

	Editor.Shapes.Literal.prototype.draw = function () {
		Editor.Shapes.Literal.superClass_.draw.call(this);
		this.corner.draw();
		this.deckEdit.draw();
		this.deckEdit.redraw();
		//this._resize(Editor.CONFIG.LITERAL_SHAPE_WIDTH - this.getWidth(), Editor.CONFIG.LITERAL_SHAPE_HEIGHT - this.getHeight());
	}

	Editor.Shapes.Literal.prototype.addInProperties = function (propUuid) {
		this.inProperties.push(propUuid);
	}

	Editor.Shapes.Literal.prototype.removeInProperties = function (propUuid) {
		var deleted = false;
		for (var i = 0; i < this.inProperties.length; i++) {
			if (!deleted && this.inProperties[i] == propUuid) {
				this.inProperties.splice(i, 1);
				deleted = true;
			}
		}
	}

	Editor.Shapes.Literal.prototype._remove = function () {
		Editor.Shapes.Literal.superClass_._remove.call(this);
		this.corner.remove();
		this.deckEdit.remove();
	}

	Editor.Shapes.Literal.prototype.remove = function () {
		var arrProperties = Array();
		for (var i = 0; i < this.inProperties.length; i++) {
			var s = Editor.STATE.SHAPES.get(this.inProperties[i]);
			if (!s.getIsDeleted()) {
				arrProperties.push(this.inProperties[i]);
			}
		}

		var shape = this;
		var corner = this.corner;
		var deckEdit = this.deckEdit;
		var impl = this.impl;
		var arrConnections = new Array();

		var cmd = new JS.Command({
			execute: function () {
				Editor.Shapes.Literal.superClass_.remove.call(impl);
				corner.remove();
				deckEdit.remove();
				for (var i = 0; i < arrProperties.length; i++) {
					var s = Editor.STATE.SHAPES.get(arrProperties[i]);
					if (!s.getIsDeleted()) {
						s._remove();
						Editor.Util.removeConnections(s.getUuid(),arrConnections);
					}
				}
				Editor.Util.removeConnections(impl.getUuid(),arrConnections);
			},
			undo: function () {
				impl.draw();
				for (var i = 0; i < arrProperties.length; i++) {
					var s = Editor.STATE.SHAPES.get(arrProperties[i]);
					if (s.getIsDeleted()) {
						s.draw();
					}
				}
				Editor.Util.unremoveConnections(arrConnections);
			},
			stack: Editor.STATE.CMDSTACK
		});
		cmd.name = 'remove literal';
		cmd.execute();
	}

	Editor.Shapes.Literal.prototype.toFront = function () {
		Editor.Shapes.Literal.superClass_.toFront.call(this);
		this.corner.toFront();
		this.deckEdit.toFront();
		this.toFrontProperties();
	}

	Editor.Shapes.Literal.prototype.toFrontProperties = function () {
		for (var i = 0; i < this.inProperties.length; i++) {
			var p = Editor.STATE.SHAPES.get(this.inProperties[i]);
		}
	}

	Editor.Shapes.Literal.prototype.moveTo = function (x, y) {
		Editor.Shapes.Literal.superClass_.moveTo.call(this, x, y);
	}

	Editor.Shapes.Literal.prototype.translate = function (dx, dy) {
		Editor.Shapes.Literal.superClass_._translate.call(this, dx, dy);
		this.corner.translate(dx, dy);
		this.deckEdit.translate(dx, dy);
	}

	Editor.Shapes.Literal.prototype._resize = function (dw, dh) {
		Editor.Shapes.Literal.superClass_._resize.call(this, dw, dh);
		this.corner.redraw();
		this.corner.toFront();
		this.deckEdit.redraw();
		this.deckEdit.toFront();
	}

	Editor.Shapes.Literal.prototype.resize = function (dw, dh) {
		Editor.Shapes.Literal.superClass_.resize.call(this, dw, dh);
		this.corner.redraw();
		this.corner.toFront();
		this.deckEdit.redraw();
		this.deckEdit.toFront();
	}

	Editor.Shapes.Literal.prototype.showEdit = function () {
		Editor.Keys.unbind();
		Editor.STATE.SHAPETOUPDATE = this;
		$('#text').val(this.text);
		$('#lang').val(this.lang);
		$('#datatype').val(this.datatype);
		$('#dialogAddLiteral').jqm({
			overlay: 40,
			modal: true
		}).jqmShow();
	}


	// set
	Editor.Shapes.Literal.prototype.setText = function (t) {
		this.text = t;
	}

	Editor.Shapes.Literal.prototype.setLang = function (l) {
		this.lang = l;
	}

	Editor.Shapes.Literal.prototype.setDatatype = function (d) {
		this.datatype = d;
	}


	// get
	Editor.Shapes.Literal.prototype.getTypeClass = function () {
		return "literal";
	}

	Editor.Shapes.Literal.prototype.getInfo = function () {
		var str = '';
		if (Editor.CONFIG.DEBUG) {
			str = 'Literal:\n';
		}
		str += '@: ' + this.lang + '\n' + '^^: ' + this.datatype;
		if (Editor.CONFIG.DEBUG) {
			str += '\n( x:' + this.getX();
			str += ' ; y:' + this.getY();
			str += ' ; w:' + this.getWidth();
			str += ' ; h:' + this.getHeight() + ' )';
			str += '\nuuid: ' + this.getUuid();
		}
		return str;
	}

	Editor.Shapes.Literal.prototype.getText = function () {
		if (text == '') {
			return '...';
		} else {
			return this.text;
		}
	}

	Editor.Shapes.Literal.prototype.getLang = function () {
		return this.lang;
	}

	Editor.Shapes.Literal.prototype.getDatatype = function () {
		return this.datatype;
	}

	Editor.Shapes.Literal.prototype.getTextAttr = function () {
		return Editor.CONFIG.SHAPE_ATTR_TEXT;
	}

	Editor.Shapes.Literal.prototype.getFigure = function () {
		return Editor.STATE.CANVAS.rect(this.getX(), this.getY(), this.getWidth(), this.getHeight(), 0).
		attr(Editor.CONFIG.LITERAL_SHAPE_ATTR);
	}

	Editor.Shapes.Literal.prototype.getShapeAttr = function () {
		return Editor.CONFIG.LITERAL_SHAPE_ATTR;
	}

	Editor.Shapes.Literal.prototype.toString = function () {
		return 'Literal-->(' + 'Text: ' + this.text + ' ; ' + 'Lang: ' + this.lang + ' ; ' + 'Datatype: ' + this.datatype + ' ; ' + Editor.Shapes.Literal.superClass_.toString.call(this) + ')'
	}

	Editor.Shapes.Literal.prototype.getDeckEdit = function () {
		return this.deckEdit;
	}

	Editor.Shapes.Literal.prototype.getInProperties = function () {
		return this.inProperties;
	}

	Editor.Shapes.Literal.prototype.toObject = function () {
		return {
			'type': 'literal',
			'text': this.text,
			'lang': this.lang,
			'datatype': this.datatype,
			'shape': Editor.Shapes.Literal.superClass_.toObject.call(this)
		}
	}

	// event
	Editor.Shapes.Literal.prototype.mouseover = function () {
		if (!Editor.Util.isDragging()) {
			Editor.Shapes.Literal.superClass_.mouseover.call(this.impl);
			this.impl.deckEdit.mouseover();
		}
	}

	Editor.Shapes.Literal.prototype.mouseout = function () {
		if (!Editor.Util.isDragging()) {
			Editor.Shapes.Literal.superClass_.mouseout.call(this.impl);
			this.impl.deckEdit.mouseout();
		}
	}

	Editor.Shapes.Literal.prototype.mousedown = function (e) {
		if (!Editor.Util.isDragging()) {
			Editor.Shapes.Literal.superClass_.mousedown.call(this.impl, e);
		}
	}

	Editor.Shapes.Literal.prototype.click = function () {
		if (!Editor.Util.isDragging()) {
			Editor.Shapes.Literal.superClass_.click.call(this.impl);
			this.impl.deckEdit.toFront();
			this.impl.toFrontProperties();
	}
}

Editor.Shapes.Literal.prototype.onmouseup = function () {
	Editor.Shapes.Literal.superClass_.onmouseup.call(this.impl);
}
